package org.example.demo07;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;

public class Test07 {
    //7.使用字符流 修改文件内容的第一行第3个到第5个字符的内容为"还行吧"，
    // （源文件C:/test02/test.txt,文件第一行内容：你好吗，远方的客人)
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("C:\\test07\\demo2.txt");
        char[] buf = new char[12];
        int readChar = 0;
        StringWriter stringWriter = new StringWriter();
        while ((readChar = fr.read(buf)) != -1) {
            stringWriter.write(buf, 0, readChar);
        }
        int len = stringWriter.toString().length();
        String firstStr = stringWriter.toString().substring(0, 2);
        String endStr = stringWriter.toString().substring(5, len);
        String res = firstStr + "还行吧" + endStr;
        FileWriter fileWriter = new FileWriter("C:\\test07\\demo2.txt");
        fileWriter.write(res);
        fileWriter.flush();
        fileWriter.close();
        fr.close();
    }


}
